class Basic:  # 最基础的形状信息，包含位置和形状
    def __init__(self, tag, id, shape):
        self.id = id  # 创造图形是返回的id
        self.tag = tag
        self.shape = shape
        self.txt = ""
        self.color = ''

    def moveBasic(self, event, canvas):
        pass

    def createBasic(self, canvas, color=None):
        pass

    def changeColor(self, color, canvas):
        pass

    def largenBasic(self, canvas):
        pass

    def lessenBasic(self, canvas):
        pass


class Line(Basic):
    def __init__(self, tag, id, shape, coordinate):
        Basic(tag, id, shape)
        self.id = id  # 创造图形是返回的id
        self.tag = tag
        self.shape = shape
        self.txt = ""
        self.color = ''
        self.left_x = coordinate[0]  # 左顶点x坐标
        self.left_y = coordinate[1]  # 左顶点y坐标
        self.right_x = coordinate[2]  # 右顶点x坐标
        self.right_y = coordinate[3]  # 右顶点y坐标

    def moveBasic(self, event, canvas, first_x, first_y):
        self.first_x = first_x
        self.first_y = first_y
        moved_x = event.x - self.first_x
        moved_y = event.y - self.first_y
        canvas.move(self.id, int(moved_x), int(moved_y))
        self.left_x += moved_x
        self.right_x += moved_x
        self.left_y += moved_y
        self.right_y += moved_y

    def createBasic(self, canvas, color=None):
        self.id = canvas.create_line(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=color)

    def changeColor(self, color, canvas):
        canvas.delete(self.id)
        self.color = color
        self.id = canvas.create_line(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=color)

    def largenBasic(self, canvas):
        canvas.delete(self.id)
        if self.left_x > 3:
            self.left_x -= 3
            self.right_x += 3
        if self.left_y > 3:
            self.left_y -= 3
            self.right_y += 3
        self.id = canvas.create_line(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=self.color)

    def lessenBasic(self, canvas):
        canvas.delete(self.id)
        if (self.left_x + 3) < (self.right_x - 3):
            self.left_x += 3
            self.right_x -= 3
        if (self.left_y + 3) < (self.right_y - 3):
            self.left_y += 3
            self.right_y -= 3
        self.id = canvas.create_line(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=self.color)


class Rectangle(Basic):
    def __init__(self, tag, id, shape, coordinate):
        Basic(tag, id, shape)
        self.id = id  # 创造图形是返回的id
        self.tag = tag
        self.shape = shape
        self.txt = ""
        self.color = ''
        self.left_x = coordinate[0]  # 左顶点x坐标
        self.left_y = coordinate[1]  # 左顶点y坐标
        self.right_x = coordinate[2]  # 右顶点x坐标
        self.right_y = coordinate[3]  # 右顶点y坐标

    def moveBasic(self, event, canvas, first_x, first_y):
        self.first_x = first_x
        self.first_y = first_y
        moved_x = event.x - self.first_x
        moved_y = event.y - self.first_y
        canvas.move(self.id, int(moved_x), int(moved_y))
        self.left_x += moved_x
        self.right_x += moved_x
        self.left_y += moved_y
        self.right_y += moved_y

    def createBasic(self, canvas, color=None):
        self.id = canvas.create_rectangle(self.left_x, self.left_y,
                                          self.right_x, self.right_y,
                                          tags=self.tag, fill=color)

    def changeColor(self, color, canvas):
        canvas.delete(self.id)
        self.color = color
        self.id = canvas.create_rectangle(self.left_x, self.left_y,
                                          self.right_x, self.right_y,
                                          tags=self.tag, fill=color)

    def largenBasic(self, canvas):
        canvas.delete(self.id)
        if self.left_x > 3:
            self.left_x -= 3
            self.right_x += 3
        if self.left_y > 3:
            self.left_y -= 3
            self.right_y += 3
        self.id = canvas.create_rectangle(self.left_x, self.left_y,
                                          self.right_x, self.right_y,
                                          tags=self.tag, fill=self.color)

    def lessenBasic(self, canvas):
        canvas.delete(self.id)
        if (self.left_x + 3) < (self.right_x - 3):
            self.left_x += 3
            self.right_x -= 3
        if (self.left_y + 3) < (self.right_y - 3):
            self.left_y += 3
            self.right_y -= 3
        self.id = canvas.create_rectangle(self.left_x, self.left_y,
                                          self.right_x, self.right_y,
                                          tags=self.tag, fill=self.color)


class Ellipse(Basic):
    def __init__(self, tag, id, shape, coordinate):
        Basic(tag, id, shape)
        self.id = id  # 创造图形是返回的id
        self.tag = tag
        self.shape = shape
        self.txt = ""
        self.color = ''
        self.left_x = coordinate[0]  # 左上角x坐标
        self.left_y = coordinate[1]  # 左上角y坐标
        self.right_x = coordinate[2]  # 右下角x坐标
        self.right_y = coordinate[3]  # 右下角y坐标

    def moveBasic(self, event, canvas, first_x, first_y):
        self.first_x = first_x
        self.first_y = first_y
        moved_x = event.x - self.first_x
        moved_y = event.y - self.first_y
        canvas.move(self.id, int(moved_x), int(moved_y))
        self.left_x += moved_x
        self.right_x += moved_x
        self.left_y += moved_y
        self.right_y += moved_y

    def createBasic(self, canvas, color=None):
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=color)

    def changeColor(self, color, canvas):
        canvas.delete(self.id)
        self.color = color
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=color)

    def largenBasic(self, canvas):
        canvas.delete(self.id)
        if self.left_x > 3:
            self.left_x -= 3
            self.right_x += 3
        if self.left_y > 3:
            self.left_y -= 3
            self.right_y += 3
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=self.color)

    def lessenBasic(self, canvas):
        canvas.delete(self.id)
        if (self.left_x + 3) < (self.right_x - 3):
            self.left_x += 3
            self.right_x -= 3
        if (self.left_y + 3) < (self.right_y - 3):
            self.left_y += 3
            self.right_y -= 3
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=self.color)


class Round(Basic):
    def __init__(self, tag, id, shape, coordinate):
        Basic(tag, id, shape)
        self.id = id  # 创造图形是返回的id
        self.tag = tag
        self.shape = shape
        self.txt = ""
        self.color = ''
        self.left_x = coordinate[0]  # 左上角x坐标
        self.left_y = coordinate[1]  # 左上角y坐标
        self.right_x = coordinate[2]  # 右下角x坐标
        self.right_y = coordinate[3]  # 右下角y坐标

    def moveBasic(self, event, canvas, first_x, first_y):
        self.first_x = first_x
        self.first_y = first_y
        moved_x = event.x - self.first_x
        moved_y = event.y - self.first_y
        canvas.move(self.id, int(moved_x), int(moved_y))
        self.left_x += moved_x
        self.right_x += moved_x
        self.left_y += moved_y
        self.right_y += moved_y

    def createBasic(self, canvas, color=None):
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=color)

    def changeColor(self, color, canvas):
        canvas.delete(self.id)
        self.color = color
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=color)

    def largenBasic(self, canvas):
        canvas.delete(self.id)
        if self.left_x > 3 and self.left_y > 3:
            self.left_x -= 3
            self.right_x += 3
            self.left_y -= 3
            self.right_y += 3
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=self.color)

    def lessenBasic(self, canvas):
        canvas.delete(self.id)
        if (self.left_x + 3) < (self.right_x - 3) and (self.left_y + 3) < (self.right_y - 3):
            self.left_x += 3
            self.right_x -= 3
            self.left_y += 3
            self.right_y -= 3
        self.id = canvas.create_oval(self.left_x, self.left_y,
                                     self.right_x, self.right_y,
                                     tags=self.tag, fill=self.color)


class Triangle(Basic):
    def __init__(self, tag, id, shape, coordinate):
        Basic(tag, id, shape)
        self.id = id  # 创造图形是返回的id
        self.tag = tag
        self.shape = shape
        self.txt = ""
        self.color = ''
        self.left_down_x = coordinate[0]  # 左下角x坐标
        self.left_down_y = coordinate[1]  # 左下角y坐标
        self.right_down_x = coordinate[2]  # 右下角x坐标
        self.right_down_y = coordinate[3]  # 右下角y坐标
        self.up_x = coordinate[4]  # 上顶点x坐标
        self.up_y = coordinate[5]  # 上顶点y坐标

    def moveBasic(self, event, canvas, first_x, first_y):
        self.first_x = first_x
        self.first_y = first_y
        moved_x = event.x - self.first_x
        moved_y = event.y - self.first_y
        canvas.move(self.id, int(moved_x), int(moved_y))
        self.left_down_x += moved_x
        self.left_down_y += moved_y
        self.right_down_x += moved_x
        self.right_down_y += moved_y
        self.up_x += moved_x
        self.up_y += moved_y

    def createBasic(self, canvas, color=None):
        if color is None:
            self.id = canvas.create_polygon(self.left_down_x,
                                            self.left_down_y,
                                            self.right_down_x,
                                            self.right_down_y,
                                            self.up_x,
                                            self.up_y,
                                            fill="", outline="black", tags=self.tag)
        else:
            self.id = canvas.create_polygon(self.left_down_x,
                                            self.left_down_y,
                                            self.right_down_x,
                                            self.right_down_y,
                                            self.up_x,
                                            self.up_y,
                                            fill=color, outline="black", tags=self.tag)

    def changeColor(self, color, canvas):
        canvas.delete(self.id)
        self.color = color
        if color is None:
            self.id = canvas.create_polygon(self.left_down_x,
                                            self.left_down_y,
                                            self.right_down_x,
                                            self.right_down_y,
                                            self.up_x,
                                            self.up_y,
                                            fill="", outline="black", tags=self.tag)
        else:
            self.id = canvas.create_polygon(self.left_down_x,
                                            self.left_down_y,
                                            self.right_down_x,
                                            self.right_down_y,
                                            self.up_x,
                                            self.up_y,
                                            fill=color, outline="black", tags=self.tag)

    def largenBasic(self, canvas):
        canvas.delete(self.id)
        if (self.up_y - 3) > 0:
            self.up_y -= 3
        if (self.left_down_x - 3) > 0:
            self.left_down_x -= 3
            self.right_down_x += 3
        self.id = canvas.create_polygon(self.left_down_x,
                                        self.left_down_y,
                                        self.right_down_x,
                                        self.right_down_y,
                                        self.up_x,
                                        self.up_y,
                                        fill=self.color, outline="black", tags=self.tag)

    def lessenBasic(self, canvas):
        canvas.delete(self.id)
        if (self.up_y + 3) < self.right_down_y:
            self.up_y += 3
        if (self.left_down_x + 6) < self.right_down_x:
            self.left_down_x += 3
            self.right_down_x -= 3
        self.id = canvas.create_polygon(self.left_down_x,
                                        self.left_down_y,
                                        self.right_down_x,
                                        self.right_down_y,
                                        self.up_x,
                                        self.up_y,
                                        fill=self.color, outline="black", tags=self.tag)
